import { Application } from 'egg';
import {
    indexRule,
    createRule,
    destroyRule
} from '../validate/wx/search';

/**
 * 小程序路由
 */
export default (app: Application) => {
    const { header } = app.middleware;
    const { } = app;

    return {
        'search.key': {
            method: 'GET',
            path: '/xxm/search/key',
            options: {
                tags: ['search/keys'],
                description: '搜索关键词',
                handler: app.controller.wx.search.searchKey,
                middlewares: [header()],
                validate: indexRule,
            },
        },
        // 'keyword.list': {
        //     method: 'GET',
        //     path: '/xxm/keyword/list',
        //     options: {
        //         tags: ['search/list'],
        //         description: '关键字列表',
        //         handler: app.controller.wx.search.list,
        //         middlewares: [header()],
        //         validate: indexRule,
        //     },
        // },
        'search.goods': {
            method: 'GET',
            path: '/xxm/search/goods',
            options: {
                tags: ['keyword/goods'],
                description: '搜索商品',
                handler: app.controller.wx.search.searchGoods,
                middlewares: [header()],
                validate: indexRule,
            },
        },
        'search.list': {
            method: 'GET',
            path: '/xxm/keyword/list',
            options: {
                tags: ['keyword/list'],
                description: '关键词列表',
                handler: app.controller.wx.search.list,
                middlewares: [header()],
                validate: indexRule,
            },
        },
        'search.create': {
            method: 'POST',
            path: '/xxm/search/create',
            options: {
                tags: ['search/create'],
                description: '新增搜索字段',
                handler: app.controller.wx.search.create,
                middlewares: [header()],
                validate: createRule,
            },
        },
        'search.destroy': {
            method: 'DELETE',
            path: '/xxm/search/:user_id',
            options: {
                tags: ['wx/search'],
                description: '删除搜索字段',
                handler: app.controller.wx.search.destroy,
                middlewares: [header()],
                validate: destroyRule,
            },
        },
    };
};
